<?php

App::uses('CroogoAppHelper', 'Croogo.View/Helper');

class CrumbsHelper extends CroogoAppHelper {
	public function getCrumb($anchor, $link=null, $title='') {
		$arr = array(
			'anchor'	=> $anchor,
			'link'		=> $link,
			'title'		=> $title,
		);
		if (empty($arr['title']) && !empty($arr['anchor'])) {
			$arr['title'] = $arr['anchor']; 
		}
		return $arr;
	}
	
	public function printCrumbs($crumbs) {
		if (count($crumbs) == 0) {
			return '';
		}
		$links = array();
		foreach ($crumbs as $crumb) {
			if (empty($crumb['anchor'])) {
				continue;
			}
			$link = $crumb['anchor'];
			if (!empty($crumb['link'])) {
				$link = '<a href="'.$crumb['link'].'" title="'.$crumb['title'].'">'.$crumb['anchor'].'</a>';
			}
			$links[] = $link;	
		}
		return join($links, ' » ');
	}
}
